package com.thirtydays.frame.module.home.adapter

import android.graphics.Color
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.thirtydays.frame.R
import com.thirtydays.frame.data.bean.DeviceData
import com.thirtydays.frame.ui.round.RoundAppCompatTextView
import com.xm.bluetoothkotlin.BluetoothManager

/**
 * @author 小垚
 * @创建时间： 2021/5/25
 * @描述：
 **/
class DeviceAdapter : BaseQuickAdapter<DeviceData, BaseViewHolder>(R.layout.recycle_item_search_device) {
    override fun convert(holder: BaseViewHolder, item: DeviceData) {
        holder.setText(R.id.nameAtv, item.name)

        val linkAtv = holder.getView<RoundAppCompatTextView>(R.id.linkAtv)

        var filter = BluetoothManager.connectDevices.keys.filter { it == item.deviceMac }

        if (filter.isNotEmpty()) {
            linkAtv.delegate.rvbackgroundEndColor = Color.TRANSPARENT
            linkAtv.delegate.rvbackgroundStartColor = Color.TRANSPARENT
            linkAtv.setTextColor(ContextCompat.getColor(context, R.color.light_blue_600))
            linkAtv.text = "已连接"
        } else {
            linkAtv.delegate.rvbackgroundEndColor = ContextCompat.getColor(context, R.color.light_blue_600)
            linkAtv.delegate.rvbackgroundStartColor = ContextCompat.getColor(context, R.color.light_blue_600)
            linkAtv.text = "连接"
            linkAtv.setTextColor(ContextCompat.getColor(context, R.color.white))
        }
    }
}